package cl.gob.minvu.catastro.util;

import java.math.BigInteger;

/**
 * @author psep
 *
 */
public final class GenericUtil {
	
	/**
	 * @param run
	 * @param dv
	 * @return
	 */
	public static final boolean validateRun(BigInteger run, String dv) {
		if (run == null || dv == null) {
			return false;
		} else {
			int run1 = run.intValue();
			char dv1 = dv.charAt(0);
			
			if (run1 < 10000 || run1 >= 50000000) {
				return false;
			} else {
				int m = 0, s = 1;

				for (; run1 != 0; run1 /= 10) {
					s = (s + run1 % 10 * (9 - m++ % 6)) % 11;
				}

				return dv1 == (char) (s != 0 ? s + 47 : 75);
			}
		}
	}

}
